package com.sc.nft.admin.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.IdConfirmRequest;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.UserCityServerCentre;
import com.sc.nft.entity.dto.GetUserCityServerCentreListDTO;
import com.sc.nft.entity.dto.GetUserCityServerCentrePageDTO;
import com.sc.nft.entity.dto.UserCityServerCentreDTO;
import com.sc.nft.entity.dto.UserWorkRoomPageDTO;
import com.sc.nft.entity.vo.CityServerCentreExportVO;
import com.sc.nft.entity.vo.GetUserCityServerCentrePageVO;
import com.sc.nft.entity.vo.UserWorkRoomPageVO;
import com.sc.nft.entity.vo.WorkRoomExportVO;
import com.sc.nft.service.UserCityServerCentreService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/userCityServerCentre")
@Api(tags = "用户城市服务中心")
public class UserCityServerCentreController {

    private final UserCityServerCentreService userCityServerCentreService;

    @ApiOperation(value = "修改用户的城市服务中心所在地", notes = "修改用户的城市服务中心所在地", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/byUserIdSaveModel", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result byUserIdSaveModel(@RequestBody UserCityServerCentre userCityServerCentre) {
        return Result.success(userCityServerCentreService.byUserIdSaveModel(userCityServerCentre));
    }

    @ApiOperation(value = "新增用户城市服务中心", notes = "新增用户城市服务中心", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/saveUserCityServerCentre", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result saveUserCityServerCentre(@Validated  @RequestBody UserCityServerCentreDTO userCityServerCentreDTO) {
        return Result.success(userCityServerCentreService.saveUserCityServerCentre(userCityServerCentreDTO));
    }

    @ApiOperation(value = "取消用户城市服务中心", notes = "取消用户城市服务中心", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/cancelUserCityServerCentre", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result cancelUserCityServerCentre(@Valid @RequestBody IdConfirmRequest request) {
        return Result.success(userCityServerCentreService.cancelUserCityServerCentre(request.getId()));
    }

    @ApiOperation(value = "获取所有用户城市服务中心", notes = "获取所有用户城市服务中心", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getUserCityServerCentreList", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result getUserCityServerCentreList(@RequestBody GetUserCityServerCentreListDTO getUserCityServerCentreListDTO) {
        return Result.success(userCityServerCentreService.getUserCityServerCentreList(getUserCityServerCentreListDTO));
    }



    @ApiOperation(value = "分页获取城市服务中心", notes = "分页获取城市服务中心", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/selectPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<Page<GetUserCityServerCentrePageVO>> selectPage(@RequestBody GetUserCityServerCentrePageDTO getUserCityServerCentreListDTO) {
        return PageResult.success(userCityServerCentreService.selectPage(getUserCityServerCentreListDTO));
    }


    @ApiOperation(value = "初始化服务中心考核数据", notes = "初始化服务中心考核数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/exam", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result exam( ) {
        userCityServerCentreService.calComplianceData();
        return Result.success();
    }

    @ApiOperation(value = "城市服务中心导出", notes = "城市服务中心导出", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/centerServerExport", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<CityServerCentreExportVO>> centerServerExport() {
        return Result.success(userCityServerCentreService.centerServerExport());
    }
}
